package com.zc.easy.No35;

/**
 * @program: leetCode
 * @create: 2019-10-15 21:56
 * @author: zhangcong
 * @description: 搜索插入位置
 **/
public class Solution {

    public static int searchInsert(int[] nums, int target) {
        if(nums.length==0){
            return 0;
        }
        int index=nums.length/2;
        while (true){
            if(nums[index]>target){
                index=index/2;
            }else if(nums[index]<target){
                index=index+index/2;
            }else {
                return index;
            }
            System.out.println(index);
        }
    }

    public static void main(String[] args) {
        int[] arr=new int[]{1,2,3,4,6,7,8,9};
        System.out.println(searchInsert(arr,5));
    }
}
